package com.bupt.kgplatform.service.impl;

import com.alibaba.fastjson.JSONObject;

import com.bupt.kgplatform.entity.pojo.NewsInfo;
import com.bupt.kgplatform.entity.pojo.NewsInfoSearchPojo;
import com.bupt.kgplatform.mapper.NewsInfoMapper;
import com.bupt.kgplatform.service.NewsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:NewsInfoServiceImpl
 * Package:com.example.blackjavaweb.service.impl
 * Description:
 *
 * @Author QIQI_1999
 * @Creat 2023/10/8 15:10
 * @Version 1.0
 */
@Service
public class NewsInfoServiceImpl implements NewsInfoService {

    @Autowired
    private NewsInfoMapper newsInfoMapper;
    @Override
    public Object getInfo(NewsInfoSearchPojo newsInfoSearchPojo) {

        if(newsInfoSearchPojo.getSource() != null){
            List<NewsInfo> newsInfoList = newsInfoMapper.getNewsInfoAll(newsInfoSearchPojo.getSource(),(newsInfoSearchPojo.getPage()-1)* newsInfoSearchPojo.getPageSize(),newsInfoSearchPojo.getPage()*newsInfoSearchPojo.getPageSize());
            int num = newsInfoMapper.getNewsInfoNum(newsInfoSearchPojo.getSource());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("num",num);
            jsonObject.put("resultList",newsInfoList);
            return jsonObject;
        }
        return null;
    }

    @Override
    public Object getCount(NewsInfoSearchPojo newsInfoSearchPojo) {
        int num = newsInfoMapper.getNewsInfoNum(newsInfoSearchPojo.getSource());
        String data = newsInfoMapper.getNewData(newsInfoSearchPojo.getSource());

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("preview",num);
        jsonObject.put("state",data);
        return jsonObject;
    }


}
